﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration;
using System.Data;
using System.Drawing;
using System.IO.Ports;
using System.Text;
using System.Threading;
using System.Windows.Forms;

namespace DZRemoteController
{
	public partial class MainForm : Form
	{
		private GameController wbc;
		public MainForm()
		{
			InitializeComponent();
			wbc = new GameController(webBrowser);
			AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(OnUnhandledException);
			Application.ThreadException += new ThreadExceptionEventHandler(OnThreadException);
		}


		private void tsbRefresh_Click(object sender, EventArgs e)
		{
			wbc.Refresh();
		}

		private void tsbProcess_Click(object sender, EventArgs e)
		{
			wbc.ApplyRules();
		}

		private void tsbSend_Click(object sender, EventArgs e)
		{
			wbc.SendCode(tstCodePlace.Text);
		}


		private void OnThreadException(object sender, ThreadExceptionEventArgs e)
		{
			if (UnhandledExceptionForm.Display(e.Exception, this) == DialogResult.Abort)
				Close();
		}

		private void OnUnhandledException(object sender, UnhandledExceptionEventArgs e)
		{
			Invoke(new ThreadExceptionEventHandler(OnThreadException),
						 new Object[] { sender, new ThreadExceptionEventArgs((Exception)e.ExceptionObject) });
		}

	}
}
